<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="org.example.entity.User" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <style>
        :root {
            --primary: #4361ee;
            --secondary: #3f37c9;
            --accent: #4cc9f0;
            --dark: #1d3557;
            --darker: #0d1b2a;
            --light: #f8f9fa;
            --gray: #8d99ae;
        }

        /* 导航栏基础样式 */
        header {
            background-color: rgba(13, 27, 42, 0.95);
            backdrop-filter: blur(10px);
            padding: 1rem 2rem;
            position: sticky;
            top: 0;
            z-index: 1000;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
        }

        .header-container {
            max-width: 1400px;
            margin: 0 auto;
            display: flex;
            justify-content: space-between;
            align-items: center;
            flex-wrap: wrap;
        }

        /* Logo样式 */
        .logo {
            display: flex;
            align-items: center;
            gap: 15px;
            text-decoration: none;
        }

        .logo-icon {
            font-size: 2.5rem;
            color: var(--accent);
        }

        .logo-text {
            font-size: 1.8rem;
            font-weight: 700;
            color: var(--light);
            letter-spacing: 1px;
        }

        .logo-text span {
            color: var(--accent);
        }

        /* 导航链接 */
        .nav-links {
            display: flex;
            gap: 2rem;
            list-style: none;
        }

        .nav-links a {
            color: var(--light);
            text-decoration: none;
            font-weight: 500;
            font-size: 1.1rem;
            padding: 0.5rem 1rem;
            border-radius: 30px;
            transition: all 0.3s ease;
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .nav-links a:hover,
        .nav-links a.active {
            background: rgba(67, 97, 238, 0.2);
            color: var(--accent);
        }

        .nav-links a i {
            font-size: 1.2rem;
        }

        /* 认证按钮 */
        .auth-buttons {
            display: flex;
            gap: 1rem;
        }

        .btn {
            padding: 0.7rem 1.5rem;
            border-radius: 30px;
            font-weight: 600;
            font-size: 1rem;
            cursor: pointer;
            transition: all 0.3s ease;
            border: none;
            display: inline-flex;
            align-items: center;
            gap: 8px;
        }

        .btn-primary {
            background: var(--primary);
            color: white;
        }

        .btn-primary:hover {
            background: var(--secondary);
            transform: translateY(-2px);
            box-shadow: 0 4px 15px rgba(67, 97, 238, 0.4);
        }

        .btn-outline {
            background: transparent;
            border: 2px solid var(--primary);
            color: var(--primary);
        }

        .btn-outline:hover {
            background: rgba(67, 97, 238, 0.1);
            transform: translateY(-2px);
        }

        /* 用户下拉菜单 */
        .user-dropdown {
            position: relative;
            display: inline-block;
        }

        .user-username {
            cursor: pointer;
            padding: 0.7rem 1.5rem;
            background: var(--primary);
            color: white;
            border-radius: 30px;
            font-weight: 600;
            display: inline-flex;
            align-items: center;
            gap: 8px;
        }

        .dropdown-content {
            display: none;
            position: absolute;
            right: 0;
            background: white;
            min-width: 160px;
            box-shadow: 0 8px 16px rgba(0,0,0,0.2);
            z-index: 1;
            border-radius: 5px;
            overflow: hidden;
        }

        .dropdown-content a {
            color: #333;
            padding: 12px 16px;
            text-decoration: none;
            display: block;
            transition: all 0.3s ease;
        }

        .dropdown-content a:hover {
            background: #f1f1f1;
        }

        /* 个人管理下拉菜单 */
        .personal-management-dropdown {
            position: relative;
        }

        .personal-management-dropdown > a {
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .personal-dropdown-content {
            display: none;
            position: absolute;
            top: 100%;
            left: 0;
            background: white;
            min-width: 200px;
            box-shadow: 0 8px 16px rgba(0,0,0,0.2);
            z-index: 1;
            border-radius: 5px;
            overflow: hidden;
            margin-top: 5px;
        }

        .personal-dropdown-content a {
            color: #333;
            padding: 12px 16px;
            text-decoration: none;
            display: block;
            transition: all 0.3s ease;
            font-size: 0.95rem;
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .personal-dropdown-content a:hover {
            background-color: rgba(67, 97, 238, 0.1);
            color: var(--primary);
        }

        .personal-dropdown-content a i {
            width: 20px;
            text-align: center;
        }

        .caret-down {
            margin-left: 5px;
            font-size: 0.9rem;
            transition: transform 0.3s ease;
        }

        /* 响应式设计 */
        @media (max-width: 992px) {
            .header-container {
                flex-direction: column;
                gap: 1rem;
            }

            .nav-links {
                gap: 0.5rem;
                flex-wrap: wrap;
                justify-content: center;
            }

            .auth-buttons {
                margin-top: 1rem;
            }

            .personal-management-dropdown {
                width: 100%;
            }

            .personal-dropdown-content {
                position: static;
                width: 100%;
                box-shadow: none;
                margin-top: 0;
                border-radius: 0;
            }
        }
    </style>
</head>
<body>
<header>
    <div class="header-container">
        <a href="Userindex.jsp" class="logo">
            <div class="logo-icon">
                <i class="fas fa-star"></i>
            </div>
            <div class="logo-text">内容<span>评级</span>平台</div>
        </a>

        <ul class="nav-links">
            <li><a href="Userindex.jsp" class="<%= request.getRequestURI().endsWith("Userindex.jsp") || request.getRequestURI().endsWith("/") ? "active" : "" %>">
                <i class="fas fa-home"></i> 首页</a></li>
            <li><a href="movie.jsp" class="<%= request.getRequestURI().endsWith("movies.jsp") ? "active" : "" %>">
                <i class="fas fa-film"></i> 电影</a></li>
            <li><a href="book.jsp" class="<%= request.getRequestURI().endsWith("books.jsp") ? "active" : "" %>">
                <i class="fas fa-book"></i> 图书</a></li>
            <li><a href="music.jsp" class="<%= request.getRequestURI().endsWith("music.jsp") ? "active" : "" %>">
                <i class="fas fa-music"></i> 音乐</a></li>
            <li class="personal-management-dropdown">
                <a href="#" class="dropdown-toggle <%= request.getRequestURI().endsWith("personal-management.jsp") ? "active" : "" %>">
                    <i class="fas fa-user-cog"></i> 个人管理 <i class="fas fa-caret-down caret-down"></i>
                </a>
                <div class="personal-dropdown-content">
                    <a href="user-comments"><i class="fas fa-comment-alt"></i> 我的评论</a>
                    <a href="favorite"><i class="fas fa-bookmark"></i> 我的收藏</a>
                    <a href="blog-list.jsp"><i class="fas fa-history"></i> 我的日志</a>
                </div>
            </li>
        </ul>

        <div class="auth-buttons">
            <c:choose>
                <c:when test="${empty sessionScope.user}">
                    <button class="btn btn-outline" onclick="location.href='Userlogin.jsp'">
                        <i class="fas fa-sign-in-alt"></i> 登录</button>
                    <button class="btn btn-primary" onclick="location.href='Userregister.jsp'">
                        <i class="fas fa-user-plus"></i> 注册</button>
                </c:when>
                <c:otherwise>
                    <div class="user-dropdown">
                        <span class="user-username">
                            <i class="fas fa-user"></i> ${sessionScope.user.username}
                        </span>
                        <div class="dropdown-content">
                            <a href="profile.jsp"><i class="fas fa-user-cog"></i> 个人中心</a>
                            <a href="logout.jsp"><i class="fas fa-sign-out-alt"></i> 退出登录</a>
                        </div>
                    </div>
                </c:otherwise>
            </c:choose>
        </div>
    </div>
</header>

<script>
    // 下拉菜单交互
    document.addEventListener('DOMContentLoaded', function() {
        const dropdownToggles = document.querySelectorAll('.dropdown-toggle, .user-username');

        dropdownToggles.forEach(toggle => {
            toggle.addEventListener('click', function(e) {
                e.preventDefault(); // 防止默认行为

                // 关闭其他所有下拉菜单
                document.querySelectorAll('.dropdown-content, .personal-dropdown-content').forEach(content => {
                    if (content.parentElement !== toggle.parentElement) {
                        content.style.display = 'none';
                    }
                });

                // 切换当前下拉菜单的显示状态
                const content = toggle.nextElementSibling;
                content.style.display = content.style.display === 'block' ? 'none' : 'block';

                // 切换箭头方向
                const caret = toggle.querySelector('.caret-down');
                if (caret) {
                    caret.style.transform = content.style.display === 'block' ? 'rotate(180deg)' : 'rotate(0)';
                }
            });
        });

        // 点击菜单项时不关闭下拉菜单
        document.querySelectorAll('.dropdown-content a, .personal-dropdown-content a').forEach(link => {
            link.addEventListener('click', function(e) {
                // 允许链接的默认行为（导航）
                // 但阻止事件冒泡到下拉菜单，防止其关闭
                e.stopPropagation();
            });
        });

        // 点击页面其他位置关闭下拉菜单
        document.addEventListener('click', function(e) {
            if (!e.target.closest('.user-dropdown') && !e.target.closest('.personal-management-dropdown')) {
                document.querySelectorAll('.dropdown-content, .personal-dropdown-content').forEach(content => {
                    content.style.display = 'none';
                });

                // 重置所有箭头方向
                document.querySelectorAll('.caret-down').forEach(caret => {
                    caret.style.transform = 'rotate(0)';
                });
            }
        });
    });
</script>
</body>
</html>